package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.domain.dto.RoleChangeStatusDto;
import com.xht.domain.dto.RoleDto;
import com.xht.domain.entity.Role;
import com.xht.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 显示role列表
     */
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, String roleName, String status) {
        return roleService.selectRolePage(pageNum, pageSize, roleName, status);
    }

    /**
     * 在用户管理那边显示所有状态正常的角色
     */
    @GetMapping("/listAllRole")
    public ResponseResult listAllRole() {
        return roleService.listAllRole();
    }

    /**
     * 修改role 的status
     */
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleChangeStatusDto roleDto) {
        return roleService.changeStatus(roleDto);
    }

    /**
     * 添加role
     * 1\将数据加入到role表
     * 2\将数据中的menuIds加入到 role_menu表中
     */
    @PostMapping
    public ResponseResult addRole(@RequestBody RoleDto roleDto) {
        return roleService.addRole(roleDto);
    }

    /**
     * 编辑角色信息接口
     */
    @PutMapping
    public ResponseResult updateRole(@RequestBody RoleDto roleDto) {
        return roleService.updateRole(roleDto);
    }

    /**
     * 编辑角色信息-回显指定角色id信息
     */
    @GetMapping(value = "/{roleId}")
    public ResponseResult getInfo(@PathVariable Long roleId) {
        Role role = roleService.getById(roleId);
        return ResponseResult.okResult(role);
    }

    /**
     * 删除角色信息 逻辑删除
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteRole(@PathVariable Integer id) {
        return roleService.deleteRole(id);

    }

}
